import os

from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template

from ..scheduled_item import ScheduledItem

class MainPage(webapp.RequestHandler):
    def get(self):
        self.post()

    def post(self):
        user = users.get_current_user()

        if not user:
            self.redirect(users.create_login_url(self.request.uri))

        path = os.path.join('templates', 'index.html')

        self.response.out.write(
            template.render(
                path, 
                {'scheduled_items' : ScheduledItem.all()
                 }))  
